<template>
  <a-modal
    :title="'修改用户 ' + name"
    :visible="visible"
    @ok="onSubmit"
    @cancel="visible = false"
  >
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 14 }"
    >
      <a-form-model-item label="登录密码" prop="password">
        <a-input v-model="form.password" type="password" />
      </a-form-model-item>

      <a-form-model-item label="启用/禁用" prop="enable">
        <a-switch v-model="form.enable" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      id: null,
      name: '',
      form: {
        password: '',
        enable: false,
      },
      rules: {
        // password: [
        //   {
        //     required: true,
        //     message: '请输入',
        //     trigger: 'blur',
        //   },
        // ],
      },
    }
  },
  created() {
    // console.log(this.sys)
  },
  methods: {
    open(row) {
      this.id = row.id
      this.name = row.username
      this.form = {
        password: '',
        enable: row.enable,
      }
      this.visible = true
    },
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          //   console.log(this.form)
          this.axios.put(`/a/members/${this.id}`, this.form).then((res) => {
            this.visible = false
            this.$message.success('修改成功')
            this.$emit('refresh')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
}
</script>
